package demo.impl;

import demo.AbstractDiscount;

import java.math.BigDecimal;

/**
 * @author ZhouWeiBo
 * @create 2022/6/7
 */
public class DirectDiscount extends AbstractDiscount {

    private BigDecimal directCutMoney = null;
    private BigDecimal minMoney = null;

    /**
     * 构建优惠策略
     * @param minCondition 最少执行策略金额
     * @param directCutMoney 执行金额
     */
    public DirectDiscount(BigDecimal minCondition,BigDecimal directCutMoney) {
        this.minMoney = minCondition;
        this.directCutMoney = directCutMoney;
    }

    @Override
    public int order() {
        return Integer.MIN_VALUE;
    }

    @Override
    public BigDecimal discountAmount(BigDecimal bigDecimal) {
        /* 不够最小满减金额，直接返回 */
        if (minMoney.compareTo(bigDecimal) > 0){
            return bigDecimal;
        }
        /* 保证不为负数 */
        if (bigDecimal.compareTo(directCutMoney) <= 0){
            return BigDecimal.ZERO;
        }
        return bigDecimal.subtract(directCutMoney);
    }
}
